package co.edu.uniandes.entregAndes.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import co.edu.uniandes.entregAndes.fachada.EntregAndes;
import co.edu.uniandes.entregAndes.vos.EnviosValue;

/**
 * Servlet implementation class ServletUsuario
 */
public class ServletUsuario extends HttpServlet {

	private static final long serialVersionUID = 1L;

	private static EntregAndes entregAndes = EntregAndes.darInstancia();

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ServletUsuario() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String requerimiento = request.getParameter("requerimiento");

		if (requerimiento.equals("consultar")) {
			ArrayList<EnviosValue> resp =
					entregAndes.respConsultaEnviosValueMetRF2(
							request.getParameter("emailUsuario"),
							request.getParameter("tipoCriterio"),
							request.getParameter("valorCriterio"),
							request.getParameter("orden"));
			
			PrintWriter pw = response.getWriter();
			for(EnviosValue ev : resp) {
				pw.println("<b>" + ev.darId() + "</b>");
				pw.println("-- Estado:" + ev.darEstado());
				pw.println("-- Destino:" + ev.darCiudadDestino());
			}
		} else {
			response.getWriter().println("Serious error.\n All shortcuts have disappeared.\n Screen. Mind. Both are blank.");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
}
